using System;
using System.IO;
using System.IO.Compression;

namespace ProtoScratch.Common
{
	public static class ScratchCompression
	{
		public static byte[] Compress(byte[] Raw)
		{
			using (var resultStream = new MemoryStream())
			{
				using (var rawStream = new MemoryStream(Raw))
				using (var gzipStream = new GZipStream(resultStream, CompressionMode.Compress))
				{
					rawStream.CopyTo(gzipStream);
				}
				return resultStream.ToArray();
			}
		}
		
		public static byte[] Decompress(byte[] Raw)
		{
			using (var resultStream = new MemoryStream())
			{
				using (var rawStream = new MemoryStream(Raw))
				using (var gzipStream = new GZipStream(rawStream, CompressionMode.Decompress))
				{
					gzipStream.CopyTo(resultStream);
				}
				return resultStream.ToArray();
			}
		}
	}
}

